package kr.ac.ml.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ac.kr.ml.dao.ListDao;
import ac.kr.ml.vo.ContentVo;
import kr.ac.ml.mvc.Action;

public class DeptListAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		System.out.println("DeptListAction");
		ListDao dao = new ListDao();
		List<ContentVo> list = dao.getDeptList("department_name");
		int length = list.size();
		String jsonStr = "";
		
		jsonStr += "{";
		jsonStr += "\"data\":[";
		for (int i = 0; i < length; i++) {
			jsonStr += "{";
			jsonStr += "\"department_name\":\"" + list.get(i).getdeptName() + "\"";
			if(i<length-1)
			{
				jsonStr += "},";
			}
			else
				jsonStr += "}";
		}
		jsonStr += "]";
		jsonStr += "}";
		request.setAttribute("json", jsonStr);
	}

}
